
class DB {
  // Common method for cloud function calls
  async callCloudFunction(type, data) {
    try {
      const resp = await wx.cloud.callFunction({
        name: 'quickstartFunctions',
        data: { type, data }
      });
      return resp;
    } catch (e) {
      console.error(e);
      throw e;
    }
  }

  // Update 
  async update(type, data) {
    try {
      await this.callCloudFunction(type, data);
    } catch (e) {
      return { showUploadTip: true };
    }
  }

  // Add 
  async add(type, data) {
    try {
      await this.callCloudFunction(type, data);
    } catch (e) {
      return { showUploadTip: true };
    }
  }

  // Select 
  async select(type, data) {
    try {
      const resp = await this.callCloudFunction(type, data);
      return resp;
    } catch (e) {
      return { showUploadTip: true };
    }
  }

  // Delete
  async delete(type, data) {
    try {
      await this.callCloudFunction(type, data);
    } catch (e) {
      return { showUploadTip: true };
    }
  }
}
// 导出单例实例
export default new DB();

  